#ifndef slak_glui_app_h
#define slak_glui_app_h

#include <map>
#include <string>
#include <assert.h>
#include <SDL.h>

namespace slak {
	namespace glui {
		struct Screen;


		struct App {
			static const int APP_EV_BASE = 100;
			static const int QUIT = APP_EV_BASE;
			static const int USER_APP_EV_BASE = 500;
			static const int AUTO_ALLOC_EV_BASE = 50000;

			// singleton
			static App * theApp;

			SDL_Surface * sdl_screen;
			Screen * cur_screen;
			int printed;
			bool go_on;

			static std::map<std::string, int> user_event_dict;
			static int free_event_id;

			App(int width, int height, 
				slak::glui::Screen * start_screen);
			void setScreen(Screen * s);
			void run();
			void printScreen();
			virtual bool handle(SDL_Event& ev); 

			static int eventId(std::string name);

			static SDL_TimerID push(int code, void*data1=NULL, 
						void*data2=NULL, 
						unsigned int delay = 0);
			static SDL_TimerID push(std::string event_name, 
						void*data1=NULL, 
						void*data2=NULL, 
						unsigned int delay = 0);
			static SDL_TimerID loop(int code, void*data1, 
						void*data2, 
						unsigned int delay);

			static int getScreenWidth() { 
				assert(theApp);
				assert(theApp->sdl_screen);
				return theApp->sdl_screen->w;
			}
			static int getScreenHeight() { 
				assert(theApp);
				assert(theApp->sdl_screen);
				return theApp->sdl_screen->h;
			}
		};
	}
}


#endif

